<template>
	<view class="body">
		<view class="search-box">
			<input type="text" placeholder="请输入或扫描条码" class="search-input" v-model="code" @confirm="doByInput" confirm-type="search"/>
			<view class="search-btn" @tap="doByInput">
				<image src="../../static/icons/icon_search2.png" class="btn-icon"></image>
			</view>
			<!-- /btn-group -->
		</view>
		<view class="divider">
			
		</view>		
		<view class="menu-wrapper">
			名称 : {{wrhus_name}}
		</view>		
		<view class="menu-wrapper">
			货位编码 : {{wrhus_id}}--{{invent_code}}
		</view>
		<view class="menu-wrapper space">
			层数 : {{invent_layer}}
		</view>	
		<view class="menu-wrapper space">
			列数 : {{invent_column}}
		</view>	
		<view class="menu-wrapper space">
			单位 : {{part_unit}}
		</view>	
		<view class="menu-wrapper space">
			标志 : {{invent_flag}}
		</view>
		<view class="menu-wrapper space">
			容量 : {{invent_capacity}}
		</view>
		<view class="menu-wrapper space">
			虚拟 : {{invent_virtual}}
		</view>
		<view class="menu-wrapper space">
			状态 : {{invent_status}}
		</view>
		<view class="menu-wrapper">
			备注 : {{invent_comment}}
		</view>
	</view>
</template>

<script>
	import SCan from 'common/scan.js'
	
	export default {
		data() {
			return {
				code:"",
				wrhus_id:"",
				wrhus_name:"",
				invent_code:"",
				invent_comment:"",
				invent_layer:"",
				invent_column:"",
				part_unit:"",
				invent_flag:"",
				invent_capacity:"",
				invent_virtual:"",
				invent_status:"",
				index_page:''
			}
		},
		onLoad: function(options) {
			if(options.index && options.index!="undefined"){
				this.index_page=options.index;				
			}
		},
		onShow: function(){
			// // #ifdef MP-WEIXIN
			// var _this=this;
			// uni.scanCode({
			// 	success: (data) => {
			// 		_this.queryAndScan(data.result)
			// 	}
			// })
			// // #endif
			SCan.initScan(this.queryAndScan)  
		    SCan.startScan();  
		},  
		onHide:function(){  
		    SCan.stopScan();  
		},  
		onUnload:function(){
		    SCan.stopScan();
		}, 
		methods: {
			doByInput(e){
				var _this=this;
				_this.queryAndScan(_this.code)
			},
			queryAndScan(code){
				var _this=this;
				_this.code=code;
				console.log(_this.code);
				console.log(_this.code.length);
				if(_this.code!=""){
					//记录扫描记录
					var date=new Date();
					this.$config.SysConfig.TODAY_SCAN.push({
						page:'货位',
						code:_this.code,
						date:date.getHours()+':'+date.getMinutes()+":" +date.getSeconds()
					})
					
					if(this.$config.SysConfig.APP_ISONLINE){
						uni.showLoading({
							title:_this.$config.msgs.isSearching
						})
						console.log(_this.$config.SysConfig.loginedUser.loginname)
						//在线
						this.$http.scan({
							type:'cargo',
							barcode:_this.code.replace(/[\r\n]/g,"")
						}).then(res=>{			
							console.log(res)
							if(res.data.toString()!="null"){
								this.$config.SysConfig.inventlocdef_code=res.data.invent_code
								this.$config.SysConfig.wrhus_id=res.data.wrhus_id;
								this.$config.SysConfig.invent_flag=res.data.invent_flag;
								
								_this.wrhus_id=res.data.wrhus_id;
								_this.wrhus_name=res.data.wrhus_name;
								_this.invent_code=res.data.invent_code;
								_this.invent_comment=res.data.invnet_comment;
								_this.invent_layer=res.data.invent_layer;
								_this.invent_column=res.data.invent_column;
								_this.part_unit=res.data.part_unit;
								_this.invent_flag=res.data.invent_flag;
								_this.invent_capacity=res.data.invent_capacity;
								_this.invent_virtual=res.data.invent_virtual;
								_this.invent_status=res.data.invent_status;							
								
								uni.hideLoading()
								if(_this.index_page!=""){
									var url='../'+_this.index_page+'/'+_this.index_page
									uni.navigateTo({
										url:url
									})
								}
							}
							else{
								_this.$common.playErrBeep(1)
								uni.hideLoading()
								uni.showToast({
									icon:'none',
									title:res.msg,
									duration:1500
								})
								_this.wrhus_id="";
								_this.wrhus_name="";
								_this.invent_code="";
								_this.invent_comment="";
								_this.invent_layer="";
								_this.invent_column="";
								_this.part_unit="";
								_this.invent_flag="";
								_this.invent_capacity="";
								_this.invent_virtual="";
								_this.invent_status="";	
							}
						})
					}
					else {
						//离线
						// var _this=this;
						_this.$local.scan({
							type:'cargo',
							barcode:_this.code.replace(/[\r\n]/g,"")
						},(res)=>{
							// console.log(res)
							var array=JSON.parse(res.data);
							if(array.length>0){	
								_this.$config.SysConfig.inventlocdef_code=array[0]["invent_code"]
								_this.$config.SysConfig.wrhus_id=array[0]["wrhus_id"];
								_this.$config.SysConfig.invent_flag=array[0]["invent_flag"];
								
								_this.wrhus_id=array[0]["wrhus_id"];
								_this.wrhus_name=array[0]["wrhus_name"];
								_this.invent_code=array[0]["invent_code"];
								_this.invent_comment=array[0]["invent_comment"];
								_this.invent_layer=array[0]["invent_layer"];
								_this.invent_column=array[0]["invent_column"];
								_this.part_unit=array[0]["part_unit"];
								_this.invent_flag=array[0]["invent_flag"];
								_this.invent_capacity=array[0]["invent_capacity"];
								_this.invent_virtual=array[0]["invent_virtual"];
								_this.invent_status=array[0]["invent_status"];								
																
								if(_this.index_page!=""){
									var url='../'+_this.index_page+'/'+_this.index_page
									// console.log(url)
									uni.navigateTo({
										url:url
									})
								}
							}
							else{
								_this.$common.playErrBeep(1)
								// uni.showToast(this.$config.msgs.nowrhus)
								uni.showToast({
									title:_this.$config.msgs.nowrhus,
									icon:'none',
									duration:1500
								})
								_this.wrhus_id="";
								_this.wrhus_name="";
								_this.invent_code="";
								_this.invent_comment="";
								_this.invent_layer="";
								_this.invent_column="";
								_this.part_unit="";
								_this.invent_flag="";
								_this.invent_capacity="";
								_this.invent_virtual="";
								_this.invent_status="";	
							}
						})
					}
				}
				else{
					console.log("未输入")
				}
			}
		}
	}
</script>

<style>
.body{
	border-top: solid 1px #DBDBDA;
	padding: 0upx;
}
.input{
	width: 100%;
	height: 85upx;
	padding-right: 80upx;
	background: url('../../static/icons/qrcode.png') no-repeat scroll right center transparent;
}
.menu-wrapper{
	flex-direction: row;
	display: flex;
	margin-top: 25upx;
	padding: 5upx 35upx;
}
.menu-wrapper button{
	width: 160upx;
/* 	height: 85upx; */
	/* border-radius: 0; */
}

.search-box {
    display: flex;
	flex-direction: row;
	padding: 0upx 15upx;
}
.search-input {
   flex-grow: 11;
   height: 75upx;
   line-height: 80upx;
}
.search-btn {
    flex: 1;
	border: none;	
	padding: 10upx 10upx 5upx 10upx;
}
.btn-icon{
	width: 60upx;
	height: 60upx;
	line-height: 80upx;
}
.divider{
	border-top: solid 4upx #ADADAD;
	height: 1upx;
}
.space{
	margin-top: 30upx;
}
</style>
